<template>
  <div class="live-sharing">
    <search-table :url="url"
                  ref="searchtable"
                  :form="form"
                  :hideSelect="true"
                  :headParams="headParams"
                  :defaultParams="defaultParams"
                  :columns="columns">
      <!-- 搜索条件 -->
      <template slot="searchForm">
        <a-form layout="inline" :form="form">
          <a-form-item label="直播间名称">
            <a-input allowClear v-decorator="['roomName']" placeholder="请输入直播间名称"></a-input>
          </a-form-item>
          <a-form-item label="直播状态">
            <a-select allowClear
                      style="width: 195px"
                      :options="liveStatusList"
                      v-decorator="['liveStatus']"
                      placeholder="请选择直播状态" />
          </a-form-item>
          <a-form-item label="分享方式">
            <a-select allowClear
                      style="width: 195px"
                      :options="shareTypeList"
                      v-decorator="['shareType']"
                      placeholder="请选择分享方式" />
          </a-form-item>
          <a-form-item label="分享人类型">
            <a-select allowClear
                      style="width: 195px"
                      :options="shareUserTypeList"
                      v-decorator="['shareUserType']"
                      placeholder="请选择分享人类型" />
          </a-form-item>
          <a-form-item label="分享时间">
            <fast-range-picker
              v-decorator="[ 'shareStartTime-shareEndTime' ]"
            />
          </a-form-item>
        </a-form>
      </template>
      <!-- 操作栏 -->
      <template slot="oprationRow">
        <permission authority="share:export">
          <a-button @click="exportExcel"
                    type="primary"
                    icon="delete">导出</a-button>
        </permission>
      </template>
    </search-table>
  </div>
</template>
<script>
  import { findDictNameByValue,createOptionsByDict } from '@/utils/dict'
  const appId = createOptionsByDict('LIVE_APPID')[0] ? createOptionsByDict('LIVE_APPID')[0].value : '100000054' // 直播平台id
  export default {
    name: 'liveSharing',
    data() {
      return {
        headParams: { baseURL: `${location.origin}/goldenhome/gh/live/admin` },
        defaultParams: {appId: appId}, // 列表默认携带参数
        url: '/share/page', // 列表接口地址
        form: this.$form.createForm(this, { name: 'table_search' }), // 搜索表单
        liveStatusList: createOptionsByDict('LIVE_STATUS'), // 直播状态
        shareTypeList: createOptionsByDict('LIVE_SHARE_TYPE'), // 分享方式
        shareUserTypeList: createOptionsByDict('LIVE_SHARE_USER'), // 分享人类型
        columns: [
          {
            title: '分享人账号',
            dataIndex: 'sharePhone',
            key: 'sharePhone',
          },
          {
            title: '分享人身份类型',
            dataIndex: 'shareUserType',
            key: 'shareUserType',
            customRender: (text, record) => findDictNameByValue('LIVE_SHARE_USER', text)
          },
          {
            title: '分享时间',
            dataIndex: 'shareDate',
            key: 'shareDate',
          },
          {
            title: '分享方式',
            dataIndex: 'shareType',
            key: 'shareType',
            customRender: (text, record) => findDictNameByValue('LIVE_SHARE_TYPE', text)
          },
          {
            title: '直播间名称',
            dataIndex: 'roomName',
            key: 'roomName ',
          },
          {
            title: '直播时间',
            dataIndex: 'startTime',
            key: 'startTime',
            customRender: (text, row) => row.startDate+'至'+row.endDate
          },
          {
            title: '创建人账号',
            dataIndex: 'createrPhone',
            key: 'createrPhone'
          },
          {
            title: '直播状态',
            dataIndex: 'liveStatus',
            key: 'liveStatus',
            customRender: (text, record) => findDictNameByValue('LIVE_STATUS', text)
          },
          {
            title: '主播账号',
            dataIndex: 'anchorWechat',
            key: 'anchorWechat'
          },
          {
            title: '主播昵称',
            dataIndex: 'anchorName',
            key: 'anchorName',
          },
        ]
      }
    },
    methods: {
      // 导出
      exportExcel() {
        if (this.$refs.searchtable.dataSource.length == 0) {
          this.$message.warning('页面数据为空无法导出！！');
          return false
        }

        this.$export('/share/export', this.$refs.searchtable.searchParams, false, { baseURL: `${location.origin}/goldenhome/gh/live/admin` })
      }
    }
  }
</script>
